package com.example.foobar.dao.service.impl;

import com.example.foobar.dto.DABaseDTO;
import com.example.foobar.entity.DaUserChangeRecord;
import com.example.foobar.mapper.DaUserChangeRecordMapper;
import com.example.foobar.dao.service.DaUserChangeRecordDaoService;
import com.example.foobar.param.DaUserChangeRecordPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * 新增用户数记录 服务实现类
 *
 * @author 郑英奔
 * @since 2021-06-19
 */
@Slf4j
@Service
public class DaUserChangeRecordDaoServiceImpl extends BaseServiceImpl<DaUserChangeRecordMapper, DaUserChangeRecord> implements DaUserChangeRecordDaoService {

    @Autowired
    private DaUserChangeRecordMapper daUserChangeRecordMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDaUserChangeRecord(DaUserChangeRecord daUserChangeRecord)  {
        return super.save(daUserChangeRecord);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDaUserChangeRecord(DaUserChangeRecord daUserChangeRecord) {
        return super.updateById(daUserChangeRecord);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDaUserChangeRecord(Long id)  {
        return super.removeById(id);
    }

    @Override
    public Paging<DaUserChangeRecord> getDaUserChangeRecordPageList(DaUserChangeRecordPageParam daUserChangeRecordPageParam) {
        Page<DaUserChangeRecord> page = new PageInfo<>(daUserChangeRecordPageParam, OrderItem.desc(getLambdaColumn(DaUserChangeRecord::getCreateTime)));
        LambdaQueryWrapper<DaUserChangeRecord> wrapper = new LambdaQueryWrapper<>();
        IPage<DaUserChangeRecord> iPage = daUserChangeRecordMapper.selectPage(page, wrapper);
        return new Paging<DaUserChangeRecord>(iPage);
    }

    @Override
    public List<DABaseDTO> getUserActiveRate(Map<String, Object> params) {
        return daUserChangeRecordMapper.getUserActiveRate(params);
    }

    @Override
    public List<DABaseDTO> getUserActiveRateForYingMa(Map<String, Object> params) {
        return daUserChangeRecordMapper.getUserActiveRateForYingMa(params);
    }

    @Override
    public List<DABaseDTO> getQrcodeUserActiveRateforYingMa(Map<String, Object> params) {
        return daUserChangeRecordMapper.getQrcodeUserActiveRateforYingMa(params);
    }

}
